package com.ymttest.database.sqlwapper;

import java.util.List;
import java.util.stream.Collectors;

import com.ymt.database.SqlManager;
import com.ymttest.database.model.YmtProductOrderStockLog;

public class YmtProductOrderStockLogWapper {
	SqlManager manage;

	public YmtProductOrderStockLogWapper() {
		manage = new SqlManager("intpro");
	}
	
	public List<YmtProductOrderStockLog> selectByProductId(String productId)throws InterruptedException{
		  @SuppressWarnings("unchecked")
		List<YmtProductOrderStockLog>  YmtProductOrderStockLogList = manage.getSelectResults(
		            "com.ymttest.database.mapping.YmtProductOrderStockLogMapper.selectByProductId", productId);
		    manage.commit();
		    return YmtProductOrderStockLogList;
	}
	
	public List<YmtProductOrderStockLog> selectByCatalogId(String catalogId)throws InterruptedException{
		  @SuppressWarnings("unchecked")
		List<YmtProductOrderStockLog>  YmtProductOrderStockLogList = manage.getSelectResults(
		            "com.ymttest.database.mapping.YmtProductOrderStockLogMapper.selectByCatalogId", catalogId);
		    manage.commit();
		    return YmtProductOrderStockLogList;
	}
	
	
	
	
	public List<YmtProductOrderStockLog> selectByOrderId(int orderId)throws InterruptedException{
		  @SuppressWarnings("unchecked")
		List<YmtProductOrderStockLog>  YmtProductOrderStockLogList = manage.getSelectResults(
		            "com.ymttest.database.mapping.YmtProductOrderStockLogMapper.selectByOrderId", orderId);
		    manage.commit();
		    return YmtProductOrderStockLogList;
	}
	
	
	public List<YmtProductOrderStockLog> selectByOrderId(long orderId)throws InterruptedException{
		  @SuppressWarnings("unchecked")
		List<YmtProductOrderStockLog>  YmtProductOrderStockLogList = manage.getSelectResults(
		            "com.ymttest.database.mapping.YmtProductOrderStockLogMapper.selectByOrderId", orderId);
		    manage.commit();
		    return YmtProductOrderStockLogList;
	}
	
	
	
	public static void main(String[] args) throws InterruptedException {
		List<YmtProductOrderStockLog> ymtProductOrderStockLogList = new YmtProductOrderStockLogWapper().selectByCatalogId("d1672d56-5225-4643-a9b6-1f6b26a7a38b");
		
		int a = ymtProductOrderStockLogList
				.stream().filter(x->x.getActivityId()==0)
				.map(y->y.getStockNum())
				.collect(Collectors.summingInt(Integer::intValue));
		
		
		
		System.out.println(a);
		
	}
}
